import logging

import pytest

from resource.pom.memorandum import Memorandum


class Test:
    app = Memorandum

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('预置条件.清除测试数据')
        device.hdc_shell('rm -rf /data/app/el2/100/database/com.ohos.note/default/rdb/note.db')
        device.wait(2)
        logging.info('步骤1.进入桌面，点击备忘录，新增笔记')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        device.click(*self.app.add_note)
        logging.info('预期结果1.可正常新增笔记')
        device.refresh_layout()
        device.assert_text_exist('标题')
        device.assert_text_exist('未分类')
        device.assert_type_exist('rootWebArea')

        logging.info('步骤2.删除笔记')
        device.click(*self.app.del_note)
        device.refresh_layout()
        device.click_element(device.get_element_by_text('删除'))
        logging.info('预期结果2.最近删除中显示对应已删除的笔记')
        device.wait(1)
        device.click(*self.app.open_menu)
        device.click(*self.app.recent_delete)
        device.click(*self.app.close_menu)
        device.refresh_layout()
        device.assert_text_exist('标题')

        logging.info('步骤3.进入最近删除，点击笔记，点击恢复按钮')
        device.click_element(device.get_element_by_text('标题'))
        device.click(*self.app.recover_from_dustbin)
        logging.info('预期结果3.笔记恢复至原来的位置，最近删除中笔记数量相应减少')
        device.go_back()
        device.refresh_layout()
        device.assert_text_exist('标题', expect=False)
        device.click(*self.app.open_menu)
        device.click(*self.app.all_note)
        device.click(*self.app.close_menu)
        device.refresh_layout()
        device.assert_text_exist('标题')
